package cn.com.lei.du.controller;

import cn.com.lei.du.entity.User;
import cn.com.lei.du.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import rx.Observable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getUser")
    public Object getUser(){
         return userService.getUser();
    }

    @GetMapping("/getUserByName")
    public User getUserByName(@RequestParam("name") String name){
        return userService.getUserByName(name);
    }

    @GetMapping("/getUserByNameMap")
    public User getUserByNameMap(@RequestParam("name") String name){
        return userService.getUserByNameMap(name);
    }

    @GetMapping("/postUserByName")
    public User postUserByName(@RequestParam("name") String name){
        return userService.postUserByName(name);
    }

    @GetMapping("/postUserByNameMap")
    public User postUserByNameMap(@RequestParam("name") String name){
        return userService.postUserByNameMap(name);
    }

    @GetMapping("/postUserByRequestBody")
    public Object postUserByRequestBody(@RequestParam("name") String name){
        return userService.postUserByRequestBody(name);
    }

    @GetMapping("/postUserByRequestBodyAsy")
    public Object postUserByRequestBodyAsy(@RequestParam("name") String name) throws ExecutionException, InterruptedException {
        Future<User> future = userService.postUserByRequestBodyAsy(name);
        return future.get();
    }

    @GetMapping("/observe")
    public Object observe(@RequestParam("name") String name) throws InterruptedException {
        Observable<User> observable = userService.observe(name);
        return new User();
    }

}
